﻿@model EntityPickerModel
@{
    var selectIds = string.IsNullOrEmpty(Model.SelectedIds) ? new List<string>() : Model.SelectedIds.Split(',').ToList();
}
@helper HighlightSearchTermInTitle(EntityPickerModel.SearchResultModel item)
{
if (Model.HighligtSearchTerm && Model.SearchTerm.HasValue() && item.Title.HasValue())
{

        @Html.Raw(item.Title.Replace(Model.SearchTerm, "<span class=\"highlight\">{0}</span>".FormatInvariant(Model.SearchTerm), StringComparison.OrdinalIgnoreCase))
}
else
{
        @item.Title
}
}
@functions {
    public string CheckSelect(List<string> selectIds, int id)
    {

        return selectIds.Where(x => x == id.ToString()).Any() ? " selected" : "";
    }

}


@foreach (var item in Model.SearchResult ?? Enumerable.Empty<EntityPickerModel.SearchResultModel>())
{
    <div class="item-wrap">
        <div class="item@(item.Disable ? " disable" : "")@(CheckSelect(selectIds,item.Id))" data-id="@item.Id" data-returnvalue="@item.ReturnValue">

            @if (item.ImageUrl.HasValue())
                {

                <div class="thumb">
                    <img src="@item.ImageUrl" alt="" />
                </div>
            }

            <div class="data">
                <div class="title" title="@item.Title">
                    @if (item.LabelText.HasValue())
                    {
                        <span class="label @item.LabelClassName">@item.LabelText</span>
                    }
                    <span>@HighlightSearchTermInTitle(item)</span>
                </div>
                <div>
                    @if (item.Published.HasValue)
                    {
                        <i class="published fa @(item.Published.Value ? "fa-globe" : "fa-eye-slash") xicon-active-@item.Published.Value.ToString().ToLower()" title="@(item.Published.Value ? Model.PublishedString : Model.UnpublishedString)"></i>
                    }
                    <span class="summary" title="@item.SummaryTitle">@item.Summary</span>
                </div>
            </div>
        </div>
    </div>
}
<div class="list-footer">
    @if (Model.SearchResult == null || Model.SearchResult.Count == 0)
    {
        @T("Common.EntityPicker.NoMoreItemsFound")
    }
    else if (Model.SearchResult.Count == Model.PageSize)
    {
        <span class="load-more">&nbsp;</span>
    }
    else if (Model.PageIndex > 0)
    {
        @T("Common.EntityPicker.NoMoreItemsFound")
    }
</div>